import * as mongoose from 'mongoose';

import fastFormatTimeSchema, { noIdSchema } from './base';

const { Schema } = mongoose;

const userSchema = new Schema(
  {
    username: Schema.Types.String,
    password: Schema.Types.String,
    nickName: Schema.Types.String,
    avatar: Schema.Types.String,
    lastLogin: Schema.Types.String,
    ...fastFormatTimeSchema(),
  },
  {
    versionKey: false,
    timestamps: true,
    toJSON: {
      getters: true,
      transform(doc, ret) {
        ret.id = ret._id;
        delete ret._id;
      },
    },
    toObject: {
      getters: true,
      transform(doc, ret) {
        ret.id = ret._id;
        delete ret._id;
      },
    },
  },
);

export default userSchema;
